import { getServerSession } from "next-auth";
import prismadb from "./prismadb";
import { authOptions } from "./auth";

const serverAuth = async ()=>{
    const session = await getServerSession(authOptions)
    if(!session?.user?.email){
        throw new Error("Not signIn in")
    }
    const currentUser = await prismadb.user.findUnique({
        where: {
            email: session.user.email,
        }
    })
    if (!currentUser) {
        throw new Error("Not signIn in")
    }
    return {currentUser}
}

export default serverAuth